cosine similiarity OF A VECTOR WITH OTHER VECTORS IN A MATRIX

37

a = np.random.randint(0,10,(5,5))
print(a)
array([[5, 2, 0, 4, 1],
       [4, 2, 8, 2, 4],
       [9, 7, 4, 9, 7],
       [4, 6, 0, 1, 3],
       [1, 1, 2, 5, 0]])

from sklearn.metrics.pairwise import cosine_similarity
cosine_similarity(a[None,:,-1] , a.T[:-1])
# array([[0.94022805, 0.91705665, 0.75592895, 0.79921221, 1.        ]])

Comments

Submit
0 Comments